/*     */ package com.zimbra.cs.account.callback;
/*     */ 
/*     */ import com.zimbra.cs.account.AttributeCallback;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.zimlet.ZimletPresence;
/*     */ import com.zimbra.cs.zimlet.ZimletPresence.Presence;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class AvailableZimlets
/*     */   extends AttributeCallback
/*     */ {
/*     */   public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry)
/*     */   {
/*  32 */     Object replacing = attrsToModify.get(attrName);
/*  33 */     Object deleting = attrsToModify.get("-" + attrName);
/*  34 */     Object adding = attrsToModify.get("+" + attrName);
/*     */     ZimletPresence availZimlets;
/*     */     ZimletPresence availZimlets;
/*  37 */     if (replacing != null) {
/*  38 */       availZimlets = doReplacing(replacing);
/*     */     } else {
/*  40 */       availZimlets = doDeletingAdding(entry, attrName, deleting, adding);
/*     */     }
/*  42 */     String[] zimlets = availZimlets.getZimletNamesAsArray();
/*  43 */     String[] newValues = new String[zimlets.length];
/*  44 */     for (int i = 0; i < zimlets.length; i++) {
/*  45 */       String zimletName = zimlets[i];
/*  46 */       ZimletPresence.Presence presence = availZimlets.getPresence(zimletName);
/*  47 */       newValues[i] = (presence.prefix() + zimletName);
/*     */     }
/*     */     
/*     */ 
/*  51 */     attrsToModify.remove(attrName);
/*  52 */     attrsToModify.remove("-" + attrName);
/*  53 */     attrsToModify.remove("+" + attrName);
/*  54 */     attrsToModify.put(attrName, newValues);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   private ZimletPresence doReplacing(Object replacing)
/*     */   {
/*  61 */     ZimletPresence availZimlets = new ZimletPresence();
/*     */     
/*     */ 
/*     */ 
/*  65 */     if ((replacing instanceof String)) {
/*  66 */       availZimlets.put((String)replacing);
/*  67 */     } else if ((replacing instanceof String[])) {
/*  68 */       for (String v : (String[])replacing) {
/*  69 */         availZimlets.put(v);
/*     */       }
/*     */     }
/*  72 */     return availZimlets;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private ZimletPresence doDeletingAdding(Entry entry, String attrName, Object deleting, Object adding)
/*     */   {
/* 103 */     ZimletPresence availZimlets = new ZimletPresence();
/*     */     
/*     */ 
/* 106 */     if (entry != null) {
/* 107 */       String[] curValues = entry.getMultiAttr(attrName, false);
/* 108 */       for (String zimletWithPrefix : curValues) {
/* 109 */         availZimlets.put(zimletWithPrefix);
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*     */ 
/* 115 */     if (deleting != null) {
/* 116 */       if ((deleting instanceof String)) {
/* 117 */         availZimlets.remove((String)deleting);
/*     */       } else {
/* 119 */         for (String v : (String[])deleting) {
/* 120 */           availZimlets.remove(v);
/*     */         }
/*     */       }
/*     */     }
/*     */     
/*     */ 
/* 126 */     if (adding != null) {
/* 127 */       if ((adding instanceof String)) {
/* 128 */         availZimlets.put((String)adding);
/* 129 */       } else if ((adding instanceof String[])) {
/* 130 */         for (String v : (String[])adding) {
/* 131 */           availZimlets.put(v);
/*     */         }
/*     */       }
/*     */     }
/* 135 */     return availZimlets;
/*     */   }
/*     */   
/*     */   public void postModify(CallbackContext context, String attrName, Entry entry) {}
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/callback/AvailableZimlets.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */